package cn.com.pansky.action.logs;

import java.sql.Timestamp;
import java.util.UUID;

import net.vsame.url2sql.action.CommonAction;
import net.vsame.url2sql.helper.SqlHelper;

public class Log extends CommonAction {
	/**
	 * 开始记录
	 * @param CA001	好友id
	 * @param AF004	办理业务类型
	 * @return 日志表id/0
	 */
	public String start(String CA001,String AF004){
		//AF001,AA001,CA001,AF002,AF003,AF004,AF005,AF006
		//流水id，用户id，好友id，开始时间，结束时间，业务详情,结果,结果详情
		String startSQL = "insert into RA20(AF001,AA001,CA001,AF002,AF004) values(?,?,?,?,?) ";
		String AF001 = UUID.randomUUID().toString();//uuid
		String AA001 = user.getString("AA001");//用户id
		
		String AF002 = new Timestamp(System.currentTimeMillis()).toString();//开始办理业务时间
		int i = SqlHelper.execute(startSQL, AF001,AA001,CA001,AF002,AF004);
		if (i == 1) return AF001;
			else 	return "0";
	}
	
	public String start(String CA001,String AA001,String AF004){
		//AF001,AA001,CA001,AF002,AF003,AF004,AF005,AF006
		//流水id，用户id，好友id，开始时间，结束时间，业务详情,结果,结果详情
		String startSQL = "insert into RA20(AF001,AA001,CA001,AF002,AF004) values(?,?,?,?,?) ";
		String AF001 = UUID.randomUUID().toString();//uuid
		String AF002 = new Timestamp(System.currentTimeMillis()).toString();//开始办理业务时间
		int i = SqlHelper.execute(startSQL, AF001,AA001,CA001,AF002,AF004);
		if (i == 1) return AF001;
			else 	return "0";
	}
	
	public String start(String AF004){
		//AF001,AA001,CA001,AF002,AF003,AF004,AF005,AF006
		//流水id，用户id，好友id，开始时间，结束时间，业务详情,结果,结果详情
		String startSQL = "insert into RA20(AF001,AA001,CA001,AF002,AF004) values(?,?,?,?,?) ";
		String AF001 = UUID.randomUUID().toString();//uuid
		String AF002 = new Timestamp(System.currentTimeMillis()).toString();//开始办理业务时间
		int i = SqlHelper.execute(startSQL, AF001, " ", " ", AF002, AF004);
		if (i == 1) return AF001;
			else 	return "0";
	}
	
	/**
	 * 结束记录
	 * @param AF001	日志表id
	 * @param AF005	办理结果
	 * @param AF006 结果详情
	 * @return true/false
	 */
	public boolean end(String AF001,Object AF005,Object AF006){
		//AF001,AA001,CA001,AF002,AF003,AF004,AF005,AF006
		//流水id，用户id，好友id，开始时间，结束时间，业务详情,结果，结果详情
		String endSQL = "update RA20 set AF003 = ?,AF005 = ?,AF006 = ? where AF001 = ?";
		String AF003 = new Timestamp(System.currentTimeMillis()).toString();//结束时间
		int i = SqlHelper.execute(endSQL, AF003,AF005,AF006,AF001);
		if (i==1) return true;
			else return false;
	}
	
	public boolean end(String AF001, Object AF005, Object AF006, String CA001, String AA001){
		//AF001,AA001,CA001,AF002,AF003,AF004,AF005,AF006
		//流水id，用户id，好友id，开始时间，结束时间，业务详情,结果，结果详情
		String endSQL = "update RA20 set AF003 = ?,CA001 = ?, AA001 = ?, AF005 = ?, AF006 = ? where AF001 = ?";
		String AF003 = new Timestamp(System.currentTimeMillis()).toString();//结束时间
		int i = SqlHelper.execute(endSQL, AF003, CA001, AA001, AF005, AF006, AF001);
		if (i==1) return true;
			else return false;
	}
	
	
}
